package hang.xipujewelWeb.entity.account;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.validator.constraints.NotBlank;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import hang.xipujewelWeb.entity.OperateEntity;

/**
 * @Title: Role.java
 * @Package hang.xipujewelWeb.entity.account
 * @Description: 角色
 * @Date 2013-9-26-上午11:18:24
 * @Author: qizai
 * @Version: V1.0.0
 */
@Entity
@Table(name = "os_role")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends OperateEntity {
	/** 角色名 */
	private String name;
	/** 拥有权限 */
	private String permissions;
	@NotBlank
	@Column(unique = true)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@NotBlank
	@Column(columnDefinition = "TEXT")
	public String getPermissions() {
		return permissions;
	}
	public void setPermissions(String permissions) {
		this.permissions = permissions;
	}
	@Transient
	public List<String> getPermissionList() {
		if (StringUtils.isNotBlank(permissions)) {
			return ImmutableList.copyOf(StringUtils.split(permissions, ","));
		} else {
			return Lists.newArrayList();
		}
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
